﻿/**********************************************************
 ●项目：Smartkernel
 ●公司：智能核心信息技术研发中心
 ●作者：曹艳白
 ●邮箱：caoyanbai@gmail.com
 ●创建：2008-08-10
**********************************************************/
using System;
using System.IO;

namespace Smartkernel.Log
{
    /// <summary>
    /// 基于文本的日志处理
    /// </summary>
    public static class SmartTxtLoger
    {
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="message">日志内容</param>
        /// <param name="path">日志文件的路径，没有则创建，有则续写</param>
        /// <param name="smartLogLevelType">日志级别类型</param>
        public static void Write(string message, string path, SmartLogLevelType smartLogLevelType)
        {
            string directoryName = Path.GetDirectoryName(path);
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            using (StreamWriter streamWriter = new StreamWriter(path, true))
            {
                streamWriter.WriteLine("[" + smartLogLevelType.ToString() + "]：\t\t" + message + "[" + DateTime.Now.ToLongTimeString() + "]");
            }
        }
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="path">日志文件的路径，没有则创建，有则续写</param>
        /// <param name="message">日志内容</param>
        public static void Write(string message, string path)
        {
            Write(message, path, SmartLogLevelType.Middle);
        }
    }
}
